package top.conangao.system.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.conangao.common.entity.ResponseResult;
import top.conangao.system.domain.SysMenu;
import top.conangao.system.domain.vo.SysMenuVO;
import top.conangao.system.service.SysMenuService;

import java.util.List;

/**
 * @author ConanGao
 * @since 1.0
 **/
@RestController
@RequestMapping("/menus")
@RequiredArgsConstructor
public class SysMenuController {
    private final SysMenuService sysMenuService;
    @GetMapping("/{id}")
    public ResponseResult<SysMenu> getMenu(@PathVariable("id")Long id){
        return ResponseResult.ok("获取单个菜单成功",sysMenuService.getById(id));
    }

    @GetMapping("/list")
    public ResponseResult<List<SysMenu>> listMenus(){
        return ResponseResult.ok("查询菜单列表成功",sysMenuService.list());
    }
    
    @GetMapping("/tree")
    public ResponseResult<List<SysMenuVO>> treeMenus() {
        List<SysMenuVO> sysMenuVOList = sysMenuService.treeList();
        return ResponseResult.ok("查询菜单树成功",sysMenuVOList);
    }

    @GetMapping("/page")
    public ResponseResult<Page<SysMenu>> pageMenus(Page<SysMenu> page){
        return ResponseResult.ok("查询菜单分页成功",sysMenuService.page(page, Wrappers.emptyWrapper()));
    }

    @PostMapping
    public ResponseResult<Void> saveMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.save(sysMenu);
        return ResponseResult.ok("添加菜单成功");
    }
}
